﻿using System;
using System.ComponentModel;
using System.Linq.Expressions;

namespace Wizardry
{
    public class WizardNavigationHistoryDescriptor : INotifyPropertyChanged
    {
        #region Fields

        private bool isAccessible;
        private bool isSelected;
        private string pageTitle;

        #endregion

        #region Properties

        public bool IsSelected
        {
            get
            {
                return this.isSelected;
            }
            set
            {
                if (this.isSelected != value)
                {
                    this.isSelected = value;

                    this.RaisePropertyChanged(x => x.IsSelected);
                }
            }
        }

        public bool IsAccessible
        {
            get
            {
                return this.isAccessible;
            }
            set
            {
                if (this.isAccessible != value)
                {
                    this.isAccessible = value;

                    this.RaisePropertyChanged(x => x.IsAccessible);
                }
            }
        }

        public string PageTitle
        {
            get
            {
                return this.pageTitle;
            }
            set
            {
                if (this.pageTitle != value)
                {
                    this.pageTitle = value;

                    this.RaisePropertyChanged(x => x.PageTitle);
                }
            }
        }

        #endregion

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged<T>(Expression<Func<WizardNavigationHistoryDescriptor, T>> propertyExpression)
        {
            PropertyChangedEventHandler localPropertyChanged = this.PropertyChanged as PropertyChangedEventHandler;

            if ((localPropertyChanged != null) && (propertyExpression != null))
            {
                MemberExpression body = propertyExpression.Body as MemberExpression;

                if (body != null)
                {
                    localPropertyChanged(this, new PropertyChangedEventArgs(body.Member.Name));
                }
            }
        }

        #endregion
    }
}
